package com.zpc.myvideoserver.common.security.handler;

import com.alibaba.fastjson.JSON;
import com.zpc.myvideoserver.common.util.ResponseJson;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @ClassName : JwtAuthenticationEntryPoint  //类名
 * @Description : 基础认证失败处理类  //描述
 * @Author : zpc20 //作者
 * @Date: 2023/11/2  0:57
 */

@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        // @Description : 未登录返回错误 zpc20 2023/11/4 1:52
        ResponseJson.SecurityResponse(response,new ResponseJson<>("请先登录!",HttpServletResponse.SC_UNAUTHORIZED,null));
    }
}
